import express from 'express'
import {Request,Response} from 'express'
import { parse } from 'path'
const router = express.Router()
import {searchRemark,addRemark,delRemark} from "../remarkDB/remark"
import {successMessage,errorMessage} from "../resTip/resTip"

router.get("/search",async (req:Request,res:Response)=>{
  let id = parseInt(req.query.id as string)
  let data =await new searchRemark(id as number).search()
  data.length>0?res.json(new successMessage(data)):res.json(new errorMessage("获取数据失败"))
})
router.post("/del",async (req:Request,res:Response)=>{
  let id = parseInt(req.body.id as string)
  let data = await new delRemark(id as number).del()
  console.log(data);
  
  data.affectedRows?res.json(new successMessage("删除成功")):res.json(new errorMessage("删除失败"))
  
})
router.post("/add",async (req:Request,res:Response)=>{
  let {username,time,content,dongmanId,realname} = req.body  
  let Id = parseInt(dongmanId as string)
  let data = await new addRemark(username as string,time as string,content as string,Id as number,realname as string).add()
  console.log(data);
  
  data.affectedRows?res.json(new successMessage("添加成功")):res.json(new errorMessage("添加失败"))
  
})
export default router